/**
 * @file    iap_boot.h
 * @brief   上位机升级接口
 * @author  Liuwei
 * @version 1.0.1
 * @date    2023-05-14
 * 
 * @copyright Copyright (c) 2023 JBD-Energy Storage Technology Co. LTD
 * 
 * @par 修改日志:
 * <table>
 * <tr><th>Date       <th>Version   <th>Author   <th>Description
 * <tr><td>2023-05-14 <td>1.0.1     <td>Liuwei   <td>首次创建
 * </table>
 */

#ifndef __IAP_BOOT_H_
#define __IAP_BOOT_H_

/* file includes -------------------------------------------------------------*/
#include <stdint.h>
#include "If_can.h"

/* cplusplus -----------------------------------------------------------------*/
#ifdef __cplusplus
extern "C" {
#endif

/* macro/define/typedef ------------------------------------------------------*/
#define APP_MAX_SIZE         (240) // K 
#define COM_BLUE_BOOT_RATE   (38400)
#define COM_PCS_BOOT_RATE    (115200)
#define COM_MAX_PACK_SIZE    (512)

typedef enum
{
	REMOTE_UPGRADE_NULL , 
	REMOTE_UPGRADE_SELF , 
	REMOTE_UPGRADE_S1 , 
	REMOTE_UPGRADE_S2 ,
	REMOTE_UPGRADE_S3 ,
	REMOTE_UPGRADE_S4 ,
	REMOTE_UPGRADE_ERR  ,
}upgrade_goal_type;

typedef enum
{
	COM_RATE_9600 = 0, 
	COM_RATE_14400,
	COM_RATE_19200,
	COM_RATE_38400,
	COM_RATE_56000,
	COM_RATE_57600,
	COM_RATE_115200,
	COM_RATE_128000,
	COM_RATE_230400,
	COM_RATE_256000,
	COM_RATE_460800,
	COM_RATE_500000,
	COM_RATE_512000,
	COM_RATE_600000,
	COM_RATE_750000,
	COM_RATE_921600,
	COM_RATE_1000000,
	COM_RATE_1500000,
	COM_RATE_2000000,
	
	COM_RATE_MAX ,
}com_rate_type;
/* variables -----------------------------------------------------------------*/

/*******************************************************************************
 * public API List
 ******************************************************************************/
uint8_t is_iap_upgrade_cmd(uint8_t *rx_buf , uint16_t rx_len);
uint8_t is_iap_old_upgrade_cmd(uint8_t *rx_buf , uint16_t rx_len);
uint16_t calc_sum_crc(uint8_t *puchMsg, uint16_t usDataLen);
uint8_t is_iap_can_upgrade_cmd(can_frame_type recv_msg);
void iap_boot_jump_before_deal(uint8_t com_id);
uint8_t iap_boot_reply_upgrade_cmd(uint8_t *tx_buf , uint32_t rate ,uint16_t pack_size);
uint8_t is_update_slave_cmd(uint8_t *rx_buf , uint16_t rx_len);
uint32_t app_calc_app_crc(uint32_t crc, uint32_t app_start ,uint32_t app_size, uint8_t mode);
uint8_t is_update_reply_slave_cmd(uint8_t *rx_buf , uint16_t rx_len ,uint8_t *tx_buf ,uint16_t *tx_len,uint32_t rate);
uint8_t is_remote_upgrade_cmd(uint8_t *rx_buf , uint16_t rx_len , uint8_t *tx_buf , uint16_t *tx_num);
uint8_t iap_boot_reply_old_upgrade_cmd(uint8_t *tx_buf , uint32_t rate ,uint16_t pack_size);
uint8_t is_iap_upgrade_no_addr_cmd(uint8_t *rx_buf , uint16_t rx_len);

#ifdef __cplusplus
}
#endif

#endif  /* #ifndef __IAP_BOOT_H_ */
/********** Copyright (c) 2023 JBD-Energy Storage Technology Co. LTD *********/
